<?php

class ventasclienteControlador extends Controlador 
{
	
	public function __construct()
	{
		parent::__construct();
		$this->_vista->asignartJs( array( 'ventascliente' ) );
		$this->_ventasclienteDAO = $this->cargarModelo( "ventascliente" );
	}

	public function index()
	{
		$this->_vista->titulo = 'Bienvenido...';		
		$this->_vista->render('index');
	}

	public function cargarlista() {
		$lista = $this->obtenerVcadena( "lista" );
		$filtro = $this->obtenerVcadena( "filtro" );
		$esMultiple = $this->obtenerVcadena( "esMultiple" );

	    try {
	        $lstRet = $this->_ventasclienteDAO->cargarlista($lista, $filtro, $esMultiple);

	        if(isset($lstRet)) {
		        echo json_encode(array(
		                    'success' => TRUE,
		                    'lista_ret' => $lstRet
		                ));
	        }
	    } catch (Exception $e) {
	        echo "ERROR->" . $e;
	        echo "<option value='-1'>Error</option>";
	    }
	}

	public function consultarVentascliente() {

		$fecha_inicial = $this->obtenerVcadena( "fecha_inicial" );
		$fecha_final = $this->obtenerVcadena( "fecha_final" );
		$almacen = $this->obtenerVcadena( "almacen" );
		$linea = $this->obtenerVcadena( "linea" );
		$cliente = $this->obtenerVcadena( "cliente" );
		$departamento = $this->obtenerVcadena( "departamento" );
		$producto = $this->obtenerVcadena( "producto" );

		$jsonCate = array();
		$jsonSeriesCan = array();
		$jsonSeriesDin = array();
		
		try {
	        $lstVentasCliente = $this->_ventasclienteDAO->consultarVentascliente($fecha_inicial, $fecha_final, $almacen, $linea, $cliente, $departamento, $producto);

	        if( isset($lstVentasCliente) ) {

	        	$rg_VentasCliente;

	        	for( $i = 0; $i < count($lstVentasCliente); $i++){

					$rg_VentasCliente = $lstVentasCliente[$i];

					//['Africa', 'America', 'Asia', 'Europe', 'Oceania'] categorias
					$jsonCate[] = $rg_VentasCliente["clientecedula"]. " - " . $rg_VentasCliente["clientenombre"];
					$jsonSeriesUnd[] = (double)$rg_VentasCliente["total"];
					//{name: 'Year 1800',data: [107, 31, 635, 203, 2]}, {name: 'Year 1900',data: [133, 156, 947, 408, 6]}, {name: 'Year 2008',data: [973, 914, 4054, 732, 34]}

	            }

				echo (json_encode(
					array(
						"categories" => $jsonCate,
						"series" =>  array(
							"name" => "Ventas",
							"data" => $jsonSeriesUnd
							)
						)
					)
				);
	        }

	    } catch (Exception $e) {
	        echo "ERROR->" . $e;
	        echo "<option value='-1'>Error</option>";
	    }

	}

}

?>